#ifndef _FILEINFOCACHE_H_
#define _FILEINFOCACHE_H_

#include "../Common/AllTool.h"
#include "CTMasterConn.h"

struct FileInfo
{
	std::vector< pair<tstring,int> > vLocation;
	UINT64 uSize;
	UINT64 uFileGuid;
	int iSizeChanged;
};

class FileInfoCache
{
private:
	std::map<tstring,FileInfo*> mHash;
	CRITICAL_SECTION			csMutex;
	void Lock()
	{
		EnterCriticalSection(&csMutex);
	}
	void Unlock()
	{
		LeaveCriticalSection(&csMutex);
	}
	int AllocateBlock(UINT64 uFileGuid,int iPartId,tstring &tsIp,int &iPort);
	int SetFileSize(tstring tsFilename,UINT64 uFileSize);
public:
	FileInfoCache();
	~FileInfoCache();
	void DeleteCache(tstring tsFilename);
	int RefreshCache(tstring tsFilename);
	int CacheReadFile(tstring tsFilename,UINT64 uOffset,DWORD dwLength,UINT64 &uFileGuid,DWORD &dwCanReadSize,tstring &tsChunkIp,int &iChunkPort);
	int CacheWriteFile(tstring tsFilename,UINT64 uOffset,DWORD dwLength,UINT64 &uFileGuid,DWORD &dwCanWriteSize,tstring &tsChunkIp,int &iChunkPort);
	int FlushFileSize(tstring tsFilename);
};
#endif